﻿<cfsilent>
	<cfscript>

		event.setArg("pageTitle", "教学运行管理 - 考试安排 - 期末考试安排时间与地点");

		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");

		termId = event.getArg("TermID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		currentTab = event.getArg("TabID", "labNone");
		
		passArgs = structNew();
		
		targetArgs = structNew();
		structInsert(targetArgs, "TID", termId);
	
		sql = "SELECT 
					t_examtask.task_exid,
					t_course.course_name, 
					t_campus.campus_name,
					t_examtask.wid, 
					t_examtask.examer_sum, 
					t_institute.institute_short 
				FROM 
					t_examtask 
					INNER JOIN t_course ON t_course.cid = t_examtask.cid 
					INNER JOIN t_campus ON t_campus.campus_id = t_examtask.campus_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_examtask.term_id = :termId 
					AND 
					t_examtask.task_prog = '0' 
					AND 
					t_examtask.exam_type = 'F' 
				ORDER BY 
					t_institute.institute_short, t_course.course_name, t_examtask.wid "; 
		
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_task = queryObj.execute( sql=sql ).getResult();
		
	
												
		sql = "SELECT 
				  t_examtask.task_exid,
				  t_course.course_name, 
				  t_campus.campus_name,
				  t_examtask.wid, 
				  t_examtask.examer_sum, 
				  t_institute.institute_short, 
				  t_examtask.wdidx,
				  t_examtask.cellidx  
				FROM 
				  t_examtask 
				  INNER JOIN t_course ON t_course.cid = t_examtask.cid 
				  INNER JOIN t_campus ON t_campus.campus_id = t_examtask.campus_id 
				  INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
				  t_examtask.term_id = :termId 
				  AND 
				  t_examtask.task_prog = '1' 
				  AND 
				  t_examtask.exam_type = 'F' 
				ORDER BY 
				  t_institute.institute_short, t_course.course_name, t_examtask.wid  "; 
		
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_taskTimeOnly = queryObj.execute( sql=sql ).getResult();
		
		sql = "SELECT 
					t_examtask.task_exid,
					t_course.course_name, 
					t_campus.campus_name,
					t_examtask.wid, 
					t_examtask.examer_sum, 
					t_institute.institute_short, 
					t_examtask.wdidx,
					t_examtask.cellidx, 
					(SELECT COUNT(*) FROM t_clsroom_forexam WHERE t_clsroom_forexam.task_exid = t_examtask.task_exid) countCls      
				FROM 
					t_examtask 
					INNER JOIN t_course ON t_course.cid = t_examtask.cid 
					INNER JOIN t_campus ON t_campus.campus_id = t_examtask.campus_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_examtask.term_id = :termId 
					AND 
					t_examtask.task_prog = '2' 
					AND 
					t_examtask.exam_type = 'F' 
				ORDER BY 
					t_examtask.wid, t_institute.institute_short, t_course.course_name "; 
		
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_taskPlaceDone = queryObj.execute( sql=sql ).getResult();
	
												
		sql = "SELECT 
					t_examtask.task_exid,
					t_course.course_name, 
					t_campus.campus_name,
					t_examtask.wid, 
					t_examtask.examer_sum, 
					t_institute.institute_short, 
					t_examtask.wdidx,
					t_examtask.cellidx, 
					(SELECT COUNT(*) FROM t_clsroom_forexam WHERE t_clsroom_forexam.task_exid = t_examtask.task_exid) countCls      
				FROM 
					t_examtask 
					INNER JOIN t_course ON t_course.cid = t_examtask.cid 
					INNER JOIN t_campus ON t_campus.campus_id = t_examtask.campus_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_examtask.term_id = :termId 
					AND 
					t_examtask.task_prog = '3' 
					AND 
					t_examtask.exam_type = 'F' 
				ORDER BY 
					t_examtask.wid, t_institute.institute_short, t_course.course_name "; 
		
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_taskPublish = queryObj.execute( sql=sql ).getResult();

		if ( currentTab eq "labNone" and rs_task.recordCount eq 0 and rs_taskTimeOnly.recordCount gt 0 ) {
			currentTab = event.getArg("TabID", "labTimeOnly");
		}
		
		if ( currentTab eq "labNone" and rs_task.recordCount eq 0 and rs_taskPlaceDone.recordCount gt 0 ) {
			currentTab = event.getArg("TabID", "labDone");
		}
		
		if ( currentTab eq "labNone" and rs_task.recordCount eq 0 and rs_taskPublish.recordCount gt 0 ) {
			currentTab = event.getArg("TabID", "labPublished");
		}

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('examPlan')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">考试课程设置</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 exam"></i>考试时间、地点安排
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix">
			
				<div class="UItab">
					<div class="tabLables">
							<span <cfif currentTab eq "labNone">class="active"</cfif> id="labNone" tabTarget="None">未安排</span>
						<cfif rs_taskTimeOnly.recordCount>
							<span <cfif currentTab eq "labTimeOnly">class="active"</cfif> id="labTimeOnly" tabTarget="TimeOnly">仅安排时间</span>
						</cfif>
						<cfif rs_taskPlaceDone.recordCount>
							<span <cfif currentTab eq "labDone">class="active"</cfif> id="labDone" tabTarget="Done">已安排</span>
						</cfif>
						<cfif rs_taskPublish.recordCount>
							<span <cfif currentTab eq "labPublished">class="active"</cfif> id="labPublished" tabTarget="Published">已发布</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				
					<div id="None" class="tabContent">
					<cfif rs_task.recordCount>
						<div class="noticeBlock">
							<h3>尚未安排时间、地点的考试任务</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 尚有<cfoutput>#rs_task.recordCount#</cfoutput>场次考试需要安排时间和考试场地.</p>
						</div>
					
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="25"></td>
									<td width="50">任课单位</td>
									<td>课程</td>
									<td width="50">考试校区</td>
									<td width="30">周次</td>
									<td width="40">人数</td>
									<td width="25"></td>
									<td width="25"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_task"  >
									<cfset row ++ />
									<cfset structInsert(passArgs, "EXID", rs_task.task_exid, true) />
									<cfset structInsert(passArgs, "ExamType", "F", true) />
									<tr class="editRows">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_task.institute_short#</cfoutput></td>
										<td><cfoutput>#rs_task.course_name#</cfoutput></td>
										<td><cfoutput>#rs_task.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_task.wid#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_task.examer_sum#</cfoutput></span></td>
										<td><a title="自动安排时间和考试场地" class="stat arrange" href="<cfoutput>#buildURL('examTaskAuto', passArgs)#</cfoutput>"></a></td>
										<td><a title="仅指定考试时间" class="stat settime" href="<cfoutput>#buildURL('examTaskSetTime', passArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						<cfelse>
								<div class="systemNotice">
									<p>当前没有尚未安排的期末考试数据</p>
								</div>
						</cfif>
					</div>

				
				<cfif rs_taskTimeOnly.recordCount>
					<div id="TimeOnly" class="tabContent">
					
						<div class="noticeBlock">
							<h3>已指定时间的考试任务</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 尚有<cfoutput>#rs_taskTimeOnly.recordCount#</cfoutput>场次考试未安排场地和座次.</p>
						</div>
					
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="25"></td>
									<td width="50">任课单位</td>
									<td>课程</td>
									<td width="50">考试校区</td>
									<td width="30">周次</td>
									<td width="80">时间</td>
									<td width="40">人数</td>
									<td width="25"></td>
									<td width="25"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_taskTimeOnly"  >
									<cfset row ++ />
									<cfset structInsert(passArgs, "EXID", rs_taskTimeOnly.task_exid, true) />
									<cfset structInsert(passArgs, "ExamType", "F", true) />
									<tr class="editRows">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_taskTimeOnly.institute_short#</cfoutput></td>
										<td><cfoutput>#rs_taskTimeOnly.course_name#</cfoutput></td>
										<td><cfoutput>#rs_taskTimeOnly.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_taskTimeOnly.wid#</cfoutput></span></td>
										<td><cfoutput>#mathAdvice.convertWeekDayToChinese(rs_taskTimeOnly.wdidx)#</cfoutput><cfoutput>#mathAdvice.convertExamIdxToChinese(rs_taskTimeOnly.cellidx)#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_taskTimeOnly.examer_sum#</cfoutput></span></td>
										<td><a title="更改考试时间" class="stat settime" href="<cfoutput>#buildURL('examTaskSetTime', passArgs)#</cfoutput>"></a></td>
										<td><a title="自动安排考试场地" class="stat setplace" href="<cfoutput>#buildURL('examTaskSetClassroom', passArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</div>
				</cfif>
				
				<cfif rs_taskPlaceDone.recordCount>
					<div id="Done" class="tabContent">
						
						<div class="noticeBlock">
							<h3>安排时间地点的考试任务</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 有<cfoutput>#rs_taskPlaceDone.recordCount#</cfoutput>场次考试已安排.</p>
						</div>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="25"></td>
									<td width="50">任课单位</td>
									<td>课程</td>
									<td width="50">考试校区</td>
									<td width="30">周次</td>
									<td width="80">时间</td>
									<td width="40">人数</td>
									<td width="40">考场</td>
									<td width="25"></td>
									<td width="25"></td>
									<td width="25"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop  query="rs_taskPlaceDone"  >
									<cfset row ++ />
									<cfset structInsert(passArgs, "EXID", rs_taskPlaceDone.task_exid, true) />
									<cfset structInsert(passArgs, "ExamType", "F", true) />
									<tr class="editRows">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_taskPlaceDone.institute_short#</cfoutput></td>
										<td><cfoutput>#rs_taskPlaceDone.course_name#</cfoutput></td>
										<td><cfoutput>#rs_taskPlaceDone.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_taskPlaceDone.wid#</cfoutput></span></td>
										<td><cfoutput>#mathAdvice.convertWeekDayToChinese(rs_taskPlaceDone.wdidx)#</cfoutput><cfoutput>#mathAdvice.convertExamIdxToChinese(rs_taskPlaceDone.cellidx)#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_taskPlaceDone.examer_sum#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_taskPlaceDone.countCls#</cfoutput></span></td>
										<td><a title="更改考试时间" class="stat settime" href="<cfoutput>#buildURL('examTaskSetTime', passArgs)#</cfoutput>"></a></td>
										<td><a title="清除考试时间、地点安排" class="stat clear" href="javascript:clearExamTask('<cfoutput>#rs_taskPlaceDone.task_exid#</cfoutput>');"></a></td>
										<td><a title="向学生发布考试安排" class="stat publish" href="javascript:publishExamTask('<cfoutput>#rs_taskPlaceDone.task_exid#</cfoutput>');"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</div>
				</cfif>
				
				<cfif rs_taskPublish.recordCount>
					<div id="Published" class="tabContent">
						
						<div class="noticeBlock">
							<div class="operation">
								<cfset structInsert(targetArgs, "ExamType", "F", true) />
								<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('allExamPrintSitMap', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">批量打印座次表</span></a>
								<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('allExamPrintSignature', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">批量打印签到表</span></a>
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('examDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载课程考试时间、地点安排</span></a>
							</div>
							<h3>已发布考试任务</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 有<cfoutput>#rs_taskPublish.recordCount#</cfoutput>场次考试已完成安排, 并向学院发布.</p>
						</div>
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="25"></td>
									<td width="50">任课单位</td>
									<td>课程</td>
									<td width="50">考试校区</td>
									<td width="30">周次</td>
									<td width="80">时间</td>
									<td width="40">人数</td>
									<td width="40">考场</td>
									<td width="25"></td>
									<td width="25"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_taskPublish"  >
                                	<cfset row ++ />
									<cfset structInsert(passArgs, "EXID", rs_taskPublish.task_exid, true) />
									<cfset structInsert(passArgs, "ExamType", "F", true) />
									<tr class="editRows">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_taskPublish.institute_short#</cfoutput></td>
										<td><cfoutput>#rs_taskPublish.course_name#</cfoutput></td>
										<td><cfoutput>#rs_taskPublish.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_taskPublish.wid#</cfoutput></span></td>
										<td><cfoutput>#mathAdvice.convertWeekDayToChinese(rs_taskPublish.wdidx)#</cfoutput><cfoutput>#mathAdvice.convertExamIdxToChinese(rs_taskPublish.cellidx)#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_taskPublish.examer_sum#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_taskPublish.countCls#</cfoutput></span></td>
										<td><a title="清除考试时间、地点安排" class="stat clear" href="javascript:clearExamTask('<cfoutput>#rs_taskPublish.task_exid#</cfoutput>');"></a></td>
										<td><a title="查看课程考试详细安排" class="stat details" href="<cfoutput>#buildURL('examTaskPrint', passArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
					</div>
				</cfif>
				
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					function publishExamTask(examId) {
								
						$.post(
								"<cfoutput>#buildURL('apiExamTaskPublish')#</cfoutput>", 
								{
									'exid' : examId,
									'seed': (new Date()).getTime()
								}, 
								function(data) {
					
									result = $.parseJSON(data);
										
									if (result.success) {
										/* 刷新排课数据 */
										window.location.reload();
									}
									else {
										alert(result.reason);
									}
					
								});
					}
							
					function clearExamTask(examId) {
								
						$.post(
								"<cfoutput>#buildURL('apiExamTaskClear')#</cfoutput>", 
								{
									'exid' : examId,
									'seed': (new Date()).getTime()
								}, 
								function(data) {

									result = $.parseJSON(data);
										
									if (result.success) {
										/* 刷新排课数据 */
										window.location.reload();
									}
									else {
										alert(result.reason);
									}
					
								});
								
					}
					// -->
					//]]>
				</script>

			</div>
		</li>
	</ul>
</div>
